#include<bits/stdc++.h>
#define y1 Y1
#define fi first
#define endl "\n"
#define se second
#define PI acos(-1)
#define int long long
#define pb(x) push_back(x)
#define PII pair<int, int>
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define _for(i, a, b) for(int i = a; i <= b; ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;

const int N = 1e5 + 10;
int w[N], v[N], dp[1100][1100];

signed main() {
	IOS;
	int n, m;
	cin >> n >> m;
	_for(i, 1, n) {
		cin >> v[i] >> w[i];
	}
	_for(i, 1, n ) {
		for(int j = m; j >= 1; j--) {
			if(j >= v[i])
			dp[i][j] = max(dp[i - 1][j], dp[i][j - v[i]] + w[i]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

